home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 221 < prev    next >
Text File  |  1996-08-06  |  3KB  |  94 lines

  1. Path: ix.netcom.com!netnews
  2. From: kimyatta@ix.netcom.com (Darin E. Sease)
  3. Newsgroups: comp.std.c
  4. Subject: Evaluations, Comparrisons, fopen() WIN/DOS
  5. Date: Mon, 29 Jan 1996 21:19:03 GMT
  6. Organization: Netcom
  7. Message-ID: <310d3908.4601891@nntp.ix.netcom.com>
  8. NNTP-Posting-Host: ix-syr1-18.ix.netcom.com
  9. X-NETCOM-Date: Mon Jan 29 12:08:57 PM PST 1996
  10. X-Newsreader: Forte Agent .99c/16.141
  11.  
  12. Hi I'm a little confused as to what happens
  13. when this comparrison is made.
  14.  
  15. This is part of a windows program 16bit large model.
  16.  
  17. #include<windows.h>
  18. #include<stdlib.h>
  19. #include<stdio.h>
  20.  
  21. myMain()
  22. {    FILE *theFile;
  23.  
  24.     theFile = fopen( "c:\\autoexec.bat", "rt" );
  25. //-->> The compare:
  26.     if ( theFile != 0 )
  27.         MessageBox( hWnd, "fopen() Succeded!", APPNAME, MB_OK
  28. );
  29.     else
  30.     {
  31. //-->> Code allways branches here... why?
  32.         MessageBox( hWnd, "fopen() Failed!", APPNAME, MB_OK );
  33.         PostQuitMessage( 0 );
  34.         return( 0L );
  35.     }
  36.  
  37. The comparrison allways branches to the failed route weather
  38. I use "!=" or reverse it using "==".  The file does exist so
  39. I'm at a loss.  I did get this to work when I recompiled this
  40. snipit for DOS.
  41.  
  42. I use BC 4.0 and in the "NULL.H" file the "NULL" symbol is 
  43. defined as 0(zero).  I first compared the "theFile" symbol 
  44. with the "NULL" symbol, but in the watch window "NULL" was 
  45. allways undefined so I switched to 0.
  46.  
  47. In the watch window this is what I see after the fopen().
  48.  
  49. theFile == 0: 0
  50. theFile != 0: 1
  51.  
  52. Going by the watch window, the compare results in 1(True).
  53. Why then does the execution advance to the 2nd half of the else.
  54.  
  55. Below is a portion of the DOS code (it's the same thing).  I get 
  56. the same watch window results, but this branches the way I'd 
  57. expect it to.  Also the file does open (I sent it to the screen).
  58. It does not open with the windows code.
  59.  
  60. #include <stdio.h>
  61. int main( void )
  62. {    FILE *theFile;
  63.  
  64.     theFile = fopen( "c:\\autoexec.bat", "rt" );
  65.     if ( theFile != 0 )
  66.         printf("No Problem with fopen().\n");
  67.     else
  68.     {
  69. -->> Code branches to here... great!
  70.         printf("Problem with fopen().\n");
  71.         return( 0 );
  72.     }
  73.     ...
  74.     return 0;
  75. }
  76.  
  77. 1. How does the compare logic work?
  78.  
  79. 2. What about the watch var's, is there somthing about a FILE struct?
  80.  
  81. 3. Why "with the same code" do I get different results with 
  82.     DOS:    (success) code flows correctly file opens.
  83.     Windows:(failure) code flows incorrectly file won't open.
  84.     
  85. P.S. I decided to create a new file with fopen("c:\\butoexec.bat",
  86. "wt")(windows code).
  87.      the code trace said fopen() failed, but when I checked the
  88. drive it was there.
  89.  
  90. Teach a man to fish.
  91.  
  92. Thanks
  93. Darin
  94.